// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Dynamic/FREQ4Parser.h"

#include <algorithm>
#include <cstdint>
#include <iostream>

#include "boost/algorithm/string.hpp"

#include "Utility/Logging/SGLogger.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Dynamic/IFREQ4Service.h"

#include "Import/BDFImport/BDFParserBase.h"

BULKDATA_ENTRY_PARSER_REG (FREQ4);

using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure;

/*
// file://./../../Doc/MarkDown/BulkData/FREQ4/FREQ4.md>
*/

// 以下需要修改
enum FREQ4Index : std::uint8_t
{
    FREQ4Index_SID  = 1,
    FREQ4Index_F1   = 2,
    FREQ4Index_F2   = 3,
    FREQ4Index_FSPD = 4,
    FREQ4Index_NFM  = 5,
};
SG::DataStructure::Common::Status BDF::BULKDATA::ParseFREQ4 (const std::shared_ptr<SG::DBManager::DBServiceFactory>& dbServiceFactory,
                                                             std::vector<std::string>&                               dividedEntryInfo)
{
    SG::DataStructure::FEM::FREQ4Data tempFREQ4;
    tempFREQ4.m_domainId = 1;
    tempFREQ4.m_F2       = 1.0E20;
    tempFREQ4.m_FSPD     = 0.1;
    tempFREQ4.m_NFM      = 3;

    std::string curStrKey;
    for (size_t i = 1; i < 9; i++)
    {
        curStrKey          = dividedEntryInfo[i];
        bool const isEmpty = is_all_space (curStrKey);
        if (isEmpty)
        {
            continue;
        }

        switch (i)
        {
        case FREQ4Index_SID:
            tempFREQ4.m_sId = convertToI64 (curStrKey);
            break;
        case FREQ4Index_F1:
            tempFREQ4.m_F1 = convertToReal (curStrKey);
            break;
        case FREQ4Index_F2:
            tempFREQ4.m_F2 = convertToReal (curStrKey);
            break;
        case FREQ4Index_FSPD:
            tempFREQ4.m_FSPD = convertToReal (curStrKey);
            break;
        case FREQ4Index_NFM:
            tempFREQ4.m_NFM = convertToI64 (curStrKey);
            break;
        default:
            break;
        }
    }
    return dbServiceFactory->get<IFREQ4Service> ()->Add (tempFREQ4);
}